package com.zhou.yygh.user.comtroller.api;

import com.zhou.yygh.common.result.Result;
import com.zhou.yygh.common.utils.AuthContextHolder;
import com.zhou.yygh.user.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhou.hospital.model.user.Patient;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/user/patient")
@Api(tags = "就诊人管理")
public class PatientApiController {

    @Autowired
    private PatientService patientService;

    @ApiOperation(value = "获取就诊人列表")
    @GetMapping("/auth/findAll")
    public Result findAll(HttpServletRequest request) {
        Long userId = AuthContextHolder.getUserId(request);
        List<Patient> list = patientService.getPatientList(userId);
        return Result.ok(list);
    }


    @ApiOperation(value = "添加就诊人")
    @PostMapping("/auth/save")
    public Result savePatient(@RequestBody Patient patient, HttpServletRequest request) {
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return Result.ok(patient);
    }

    @ApiOperation(value = "根据就诊人ID获取就诊人信息")
    @GetMapping("/auth/get/{id}")
    public Result getPatient(@PathVariable Long id){
       Patient patient =  patientService.getPatientById(id);
      return Result.ok(patient);
    }
    @ApiOperation(value = "更新信息")
    @GetMapping("/auth/update")
    public Result updatePatient(@PathVariable Patient patient){
         patientService.updateById(patient);
        return Result.ok();
    }

    @ApiOperation(value = "删除就诊人")
    @DeleteMapping("/auth/remove{id}")
    public Result deletePatient(@PathVariable Long id) {
        patientService.removeById(id);
        return Result.ok();
    }

    //远程调用
    @ApiOperation(value = "根据就诊人Id获取就诊人信息")
    @GetMapping("/inner/get/{id}")
    public  Patient getPatientOrder(@PathVariable Long id){
        Patient patient =  patientService.getPatientById(id);
        return patient;
    }
}
